package com.beimihu.leetcode;

public class SonString {
    public static boolean isSubsequence(String s, String t) {
        int p = 0;
        int q = 0;
        int n = s.length(), m = t.length();

        while(p < n && q < m ){
            if(s.charAt(p) == t.charAt(q)){
                p++;
            }
            q++;
        }
        return p == q;
    }

    public static boolean isSubsequenceV2(String s, String t) {
        int n = s.length(), m = t.length();
        int i = 0, j = 0;
        while (i < n && j < m) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
            j++;
        }
        return i == n;
    }

    public static void main(String[] args) {
        String s = "abc";
        String t = "";

//        String s = "axc";
//        String t = "ahbgdc";
        boolean is = isSubsequenceV2(s,t);
        System.out.println(is);
    }
}
